package com.spring.library.config;

import com.spring.library.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")  // 拦截所有的请求
//                .allowedOrigins("http://localhost:5173/")  // 可跨域的域名，可以为 *
////                .allowedOrigins("http://10.111.41.49:5173/")  // 可跨域的域名，可以为 *
//                .allowCredentials(true)
//                .allowedMethods("*")   // 允许跨域的方法，可以单独配置
//                .allowedHeaders("*");  // 允许跨域的请求头，可以单独配置
//    }
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns("/library/user/login","/library/user/register");
    }
}

